package com.supreme.studyserver.config.handler;

import com.supreme.common.constant.ConsoleColors;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ColorHttpInterceptor extends DecoratorInterceptor {

    private final String consoleColor;

    public ColorHttpInterceptor(HandlerInterceptor handlerInterceptor, @NonNull String consoleColor) {
        super(handlerInterceptor);
        this.consoleColor = consoleColor;
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        return super.preHandle(request, response, handler);
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        ConsoleColors.println(this.consoleColor, "postHandle Start");
        super.postHandle(request, response, handler, modelAndView);
        ConsoleColors.println(this.consoleColor, "postHandle Finish");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        super.afterCompletion(request, response, handler, ex);
    }
}
